home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / Games / NeXTmj / Source / Help.cc < prev    next >
Text File  |  1991-03-22  |  2KB  |  97 lines

  1.  
  2. /*
  3.  $Author$
  4.  $Header$
  5.  *
  6.  $Log$
  7.  */
  8.  
  9. #import    "Help.h"
  10.  
  11. extern "Objective-C" {
  12. #import <appkit/appkit.h>
  13. }
  14.  
  15. extern "C" {
  16. #import    <assert.h>
  17.  
  18. #import    "mj.h"
  19. }
  20.  
  21.  
  22. void Help::resetHelp( void ) {
  23.  
  24.  
  25.     my_iterator = 0;
  26.     tiles_selected = NO;
  27. }
  28.  
  29.  
  30. void Help::helpClick( GameTileArray& board ) {
  31.  
  32.     int        start_tile = findNextSelectableTile( board );
  33.     
  34.     
  35.     if( start_tile != -1 ) {
  36.         BOOL            match_found = NO;
  37.         TileIterator    search_iterator;
  38.     
  39.                                                 // Find a matching tile.
  40.         do { 
  41.             int    stop_value;
  42.  
  43.             search_iterator = my_iterator.value();
  44.             stop_value = search_iterator.value();
  45.             while( !match_found && ( stop_value != ++search_iterator ))
  46.                 if( board[ search_iterator.value() ].isSelectable())
  47.                     if( board[ my_iterator.value() ].tileType() == board[ search_iterator.value() ].tileType())
  48.                         match_found = YES;
  49.  
  50.         } while( !match_found && ( start_tile != findNextSelectableTile( board )));
  51.         
  52.         if( match_found ) {
  53.         
  54.                                                 // Unselect all tiles and select
  55.                                                 //    the two that matched.
  56.             for( int k = 0; k < board.size(); ++k )
  57.                 board[ k ].setSelected( NO );
  58.             board[ my_iterator.value() ].setSelected( YES );
  59.             board[ search_iterator.value() ].setSelected( YES );
  60.  
  61.                                                 // We did select some tiles on the Game 
  62.                                                 //    Board.  Set flag for the inquisitive.
  63.             tiles_selected = YES;
  64.                                                 // At the next help pass start at the
  65.                                                 //    next tile.
  66.             ++my_iterator;
  67.         } else
  68.             NXBeep();
  69.     } else
  70.         NXBeep();
  71. }
  72.  
  73.  
  74. int Help::findNextSelectableTile( GameTileArray& board ) {
  75.  
  76.     BOOL    tile_found = NO;
  77.     int     stop_value = my_iterator.value();
  78.  
  79.  
  80.                                                 // Find a tile to search against.
  81.     while( !tile_found && ( stop_value != ++my_iterator ))
  82.         if( board[ my_iterator.value() ].isSelectable())
  83.             tile_found = YES;
  84.  
  85.     return tile_found ? my_iterator.value() : -1 ;
  86. }
  87.  
  88.  
  89.  
  90. BOOL Help::isSelected( void ) {
  91.  
  92.  
  93.     return tiles_selected;
  94. }
  95.  
  96.  
  97.